package com.uni.action;

import com.uni.entity.Commodity;
import com.uni.entity.CommodityRecord;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * --------------project-------------
 *
 * @Author Unirithe  - Mr.Chao
 * - CSDN:
 * https://blog.csdn.net/Unirithe
 * - GitHub:
 * https://github.com/unirithe
 * @create 2021/12/24 15:22
 * ------------------------------------------
 */
@WebServlet(name = "PublishPageAction", urlPatterns = "/publishPage")
public class PublishPageAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Integer publishPageNow = (Integer) session.getAttribute("publishPageNow");
        if(publishPageNow == null)
            publishPageNow = 0;
        else
            publishPageNow = (publishPageNow + 2) % ((List<Commodity>)session.getAttribute("publishInfo")).size();
        session.setAttribute("publishPageNow", publishPageNow);
        resp.sendRedirect("card_user_publish_commodity.jsp");
    }
}
